//
//  HaoBaMeHomeVC.m
//  HaoBaShengxinEn
//
//  Created by 暗流澎涌 on 2024/6/18.
//

#import "HaoBaMeHomeVC.h"
#import "RequestManager.h"
#import "HaoBaManager.h"
#import "SVProgressHUD.h"

@interface HaoBaMeHomeVC ()

@end

@implementation HaoBaMeHomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)HaoBaServerinfo:(id)sender {
    SFSafariViewController *haoBaVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://wvcbvnj2nym.feishu.cn/docx/CvBTdY6gIovuEcxoatzcEfwBnnh"]];
    [self presentViewController:haoBaVC animated:YES completion:nil];
}


- (IBAction)HaoBaPravInfo:(id)sender {
    SFSafariViewController *haoBaVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://wvcbvnj2nym.feishu.cn/docx/Jyfbdv60iouie5xQd5EcXC9Fn0d"]];
    [self presentViewController:haoBaVC animated:YES completion:nil];
}
- (IBAction)clickOntainKec:(id)sender {
    [[RequestManager sharedInstance] saveRequeseWithKey:SaveRequestTypeClick];
    BOOL isHave =  [HaoBaManager GetHaveFL] ;
    if (isHave) {
        [self haobaTOUrl];
    }else{
        [SVProgressHUD showErrorWithStatus:@"该福利已结束，感谢关注"];
    }
    
}
-(void)haobaTOUrl{
    
    [SVProgressHUD show];
    NSURL * Url = [NSURL URLWithString:[HaoBaManager HaveURl]];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSData *dataInfo = [NSData dataWithContentsOfURL:Url];
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            if (dataInfo) {
                NSDictionary *Hadict = [NSJSONSerialization JSONObjectWithData:dataInfo options:NSJSONReadingAllowFragments error:nil];
                if ([Hadict[@"status_code"] intValue] == 0) {
                    NSString *url = Hadict[@"data"][0][@"url"];
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url] options:@{} completionHandler:nil];
                } else {
                    [SVProgressHUD showErrorWithStatus:@"请求出错"];
                }
            } else {
                [SVProgressHUD showErrorWithStatus:@"请求出错"];
            }
        });
        
    });
}

@end
